feat: Add Adaptive Buffer-Aware Quality Manager (#3967)#3968
Open
Bhaumik1904 wants to merge 1 commit into
Open
feat: Add Adaptive Buffer-Aware Quality Manager (#3967)#3968Bhaumik1904 wants to merge 1 commit into
Bhaumik1904 wants to merge 1 commit into
Conversation
communism420
approved these changes
Jun 13, 2026
communism420
approved these changes
Jun 16, 2026
communism420
approved these changes
Jun 16, 2026
wahajahmed010
left a comment
There was a problem hiding this comment.
Review: Adaptive Buffer-Aware Quality Manager
Overall: Clever approach to a hard problem. The analysis that direct buffer eviction is impossible from an extension is correct, and the quality-throttling alternative is pragmatic.
Good
- Hysteresis band (restore at 60% of ceiling) prevents oscillation
- Guards for paused, live streams, and missing metadata are all correct
- Cleanup path when feature is toggled off restores original quality
- Uses playerQuality() which respects existing quality selection infrastructure
Concerns
- playerQuality(large) hardcodes 480p — May be too aggressive. On a 4K monitor, 480p looks noticeably bad. Consider making throttle quality configurable.
- Called on every 500ms tick — Runs ~14,400 times for a 2hr video. Once throttled, skip checks for N seconds since buffer won't drain instantly.
- Stale quality on manual change — If user manually changes quality while throttled, _sbmQualityBeforeThrottle could be stale. Consider resetting throttle state on manual quality change.
Nit
- Comment says large = 480p but YouTube quality labels vary. A comment referencing the actual itag would be more precise.
Verdict: No blocking issues. Approach is sound for an extension-level workaround.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3967
What this does
Implements an alternative to the "Smart Buffer Management" feature requested in #3967.
After feasibility analysis, direct buffer eviction (SourceBuffer.remove()) was confirmed impossible from a browser extension — YouTube owns its MediaSource pipeline internally and does not expose it.
This PR implements the only viable alternative: a quality manager that monitors how many seconds are buffered ahead of the playhead, and temporarily lowers stream quality when it exceeds a configurable ceiling. This prevents unbounded RAM growth on long videos by slowing down YouTube's buffering — the only lever an extension can actually control.
Changes
player.js— NewImprovedTube.smartBufferManager()functionfunctions.js— Hooked intoinitPlayer()andplayerOnTimeUpdate()core.js— Live-toggle support viacase 'smartBuffer':menu/skeleton-parts/player.js— Settings UI (toggle + slider, 30–600s, default 120s)_locales/en/messages.json— English strings added (translations welcome from contributors)How it works
video.buffered